package com.boboPlanet.user.fallback;

import com.boboPlanet.comm.enums.FeignErrorEnum;
import com.boboPlanet.comm.result.ResponseResult;
import com.boboPlanet.user.feignApi.TestApi;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2023/5/7
 * @Company planet
 **/
@Slf4j
@Component
public class TestApiFallbackImpl implements FallbackFactory<TestApi> {
    @Override
    public TestApi create(Throwable cause) {
        return new testApiImpl(cause);
    }

    public static class testApiImpl implements TestApi {

        private final Throwable cause;

        public testApiImpl(Throwable cause){
            this.cause = cause;
        }

        @Override
        public ResponseResult<String> test(String param) {
            log.error("test feign api fail, method is: {},param is: {}, exception is: {}","test",param,cause);
            return ResponseResult.feignError(FeignErrorEnum.FEIGN_SERVE_ERROR,cause);
        }
    }

}
